import { App } from 'vue'
import { vue3Frame, Options } from '@lhy-assist/vue3'
import '@lhy-assist/vue3/dist/style.css'
// import { Loader } from '@/component/lib/loader/loader'
// import { Api } from '@/plugin/axios/api'
// import { handleError, handleException } from '@/plugin/lhy-assist/error-handler'
import { AxiosError } from 'axios'
// import { logout } from '@/service/user.service'
// import { ElMessage, ElMessageBox, MessageBoxData } from 'element-plus'
import { api } from '@/config'

export default {
  install(app: App) {
    app.use(vue3Frame, {
      plugins: {
        axios: {
          defaults: {
            baseURL: api,
          },
          interceptor: {
            authorization: false,
            requestDataFormat: false,
            responseDataFormat: false,
            responseErrorFormat: false,
            // loading: {
            // showLoader: () => Loader.show(),
            // hideLoader: () => Loader.hide(),
            // },
            responseErrorHandle: {
              httpStatus: {
                401: () => {
                  // logout().then(() => {
                  //   ElMessage.warning('授权过期，请重新登录')
                  // })
                },
                500: (err: AxiosError) => {
                  // if (err.code === Api.RET_CODE.EXCEPTION_RUNTIME) {
                  //   handleException(err)
                  // } else {
                  //   handleError(err)
                  // }
                },
              },
              others: () => {
                // handleException(err)
              },
            },
          },
        },
      },
    } as Partial<Options>)
  },
}
